package com.lhy.tool.database.converter.oracle;

import com.lhy.tool.database.DbColumnType;
import com.lhy.tool.database.converter.common.AbstractDbColumnTypeMapping;
import com.lhy.tool.database.converter.ColumnTypeMappingRule;
import com.lhy.tool.database.converter.mysql.MysqlDateTimeConverter;
import org.springframework.stereotype.Component;

public class OracleColumnTypeMapping extends AbstractDbColumnTypeMapping {

    public OracleColumnTypeMapping() {
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("char"), (columnType) -> DbColumnType.STRING));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("number"), new OracleNumberConverter()));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("float"), (columnType) -> DbColumnType.FLOAT));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("date") || columnType.contains("timestamp"), new MysqlDateTimeConverter()));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("clob"), (columnType) -> DbColumnType.CLOB));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("blob"), (columnType) -> DbColumnType.BLOB));
        rules.add(new ColumnTypeMappingRule(columnType -> columnType.contains("binary") || columnType.contains("raw"), (columnType) -> DbColumnType.BYTE_ARRAY));
    }

}
